;; 一些私人的配置

;;------------------------- 设置一个周期提醒功能 开始----------------------------
;; 初始化周期alarm定时器
(defvar lugg/alarm-timer nil)
;; 默认间隔时间3600秒（1小时）
(defvar lugg/alarm-timer-cycle-time 3600)
;; 初始化alarm保持定时器
(defvar lugg/alarm-remaid-timer nil)
;; 默认提醒保持时间120秒（2分钟）
(defvar lugg/alarm-remaid-timer-time 120)

;; 进入alarm状态执行函数；会每秒钟执行一次，直到退出alarm状态
(defun lugg/alarm-in ()
  "进入alarm状态执行的功能"
  (popup-tip "休息2分钟"))

;; 退出alarm状态执行函数
(defun lugg/alarm-out ()
  "退出alarm状态执行的功能"
  (popup-tip "休息时间结束"))

;; 退出alarm状态函数
(defun lugg/alarm-remaid-timer-hook ()
  "退出alarm状态函数"
  (lugg/alarm-out)
  (when lugg/alarm-remaid-timer
	(cancel-timer lugg/alarm-remaid-timer))
  (setq lugg/alarm-remaid-timer nil)
  (lugg/start-alarm))

;; 进入alarm状态函数
(defun lugg/alarm-timer-hook ()
  "进入alarm状态函数"
  (lugg/alarm-in)
  ;; 设置每秒提醒一次，直到休息时间到
  (when lugg/alarm-timer
	(cancel-timer lugg/alarm-timer))
  (setq lugg/alarm-timer
		(run-with-timer 1 1 'lugg/alarm-in))
  (when lugg/alarm-remaid-timer
	(cancel-timer lugg/alarm-remaid-timer))
  (setq lugg/alarm-remaid-timer
		(run-with-idle-timer lugg/alarm-remaid-timer-time nil 'lugg/alarm-remaid-timer-hook)))

(defun lugg/start-alarm ()
  "开启定时提醒功能"
  (interactive)
  (when lugg/alarm-remaid-timer
	(cancel-timer lugg/alarm-remaid-timer))
  (setq lugg/alarm-remaid-timer nil)
  (when lugg/alarm-timer
	(cancel-timer lugg/alarm-timer))
  (setq lugg/alarm-timer
		(run-with-timer lugg/alarm-timer-cycle-time lugg/alarm-timer-cycle-time 'lugg/alarm-timer-hook)))

(defun lugg/stop-alarm ()
  "停止定时提醒功能"
  (interactive)
  (when lugg/alarm-remaid-timer
	(cancel-timer lugg/alarm-remaid-timer))
  (setq lugg/alarm-remaid-timer nil)
  (when lugg/alarm-timer
	(cancel-timer lugg/alarm-timer))
  (setq lugg/alarm-timer nil))
;;------------------------- 设置一个周期提醒功能 停止----------------------------

;; 默认自动开启定时提醒
(lugg/start-alarm)

(provide 'init-lugg)
